package net.adetech.crj.controller;

import com.alibaba.fastjson.JSON;
import net.adetech.crj.bean.ZggmtbForm;
import net.adetech.crj.entity.Apply;
import net.adetech.crj.entity.User;
import net.adetech.crj.utils.ServiceUtil;
import net.adetech.framework.entity.ServiceRequest;
import net.adetech.framework.entity.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class OuterApplyServiceController {

    @Autowired
    ServiceUtil serviceUtil;
    @RequestMapping(value = "/outerApply/check", produces = "application/json")
    public String submitOuterApplyPage(String formJson, HttpSession session)
    {
        ZggmtbForm form = JSON.parseObject(formJson,ZggmtbForm.class);

        User user = (User)session.getAttribute("currentUser");


        ServiceRequest request = new ServiceRequest();
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("form",form);
        params.put("user",user);
        request.setParams(params);
        ServiceResponse response = serviceUtil.call("outerApply.submit",request);


        List<Apply> applyList = (List<Apply> )response.getResults().get("applyList");
//        model.addAttribute("applyList",applyList);
//        for (Apply apply:applyList)
//        {
//            if ("OGA".equals(apply.getApplySummary()))
//            {
//                model.addAttribute("gaApply",apply);
//            }
//            if ("OTW".equals(apply.getApplySummary()))
//            {
//                model.addAttribute("twApply",apply);
//            }
//        }
        return null;

    }
}
